home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / repzip.zip / REPZIP.C next >
Text File  |  1991-02-24  |  3KB  |  148 lines

  1. //    REPZIP.C:    A program by Lindsay McCann
  2. //
  3. //    REPZIP permits the use of repeated operations with PKZIP.
  4. //    The findfirst() and findnext() functions are used to allow
  5. //    repeated invocations of PKZIP for every filename that matches
  6. //    a file specification provided by the REPZIP user.
  7. //
  8. //    USE REPZIP AT YOUR OWN RISK OR DO NOT USE IT AT ALL !
  9. //
  10. //
  11. //    To compile and link using Turbo C++ 1.0:
  12. //
  13. //    <C:\> tcc repzip.c <Enter>
  14. //
  15.  
  16.  
  17. #include    <stdio.h>
  18. #include    <conio.h>
  19. #include    <dir.h>
  20. #include    <dos.h>
  21. #include    <process.h>
  22.  
  23. #define        PROGNAME    "PKZIP.EXE"    // Name of program to spawn.
  24.  
  25. void
  26. get_ext( char *s, char *e)
  27. /*    Returns extension portion of filename
  28.     s is full filename; e points to the extension. */
  29. {
  30.     char *y;
  31.     for (y = s; (*y != '.' && *y); y++);
  32.     if(*y == '.')
  33.         for (y++; *y; e++,y++)    *e = *y;
  34.     *e = '\0';
  35.     return;
  36. }
  37.     
  38. void
  39. syntax()
  40. {
  41.     puts("\nREPZIP by Lindsay McCann");
  42.     puts("\n       SYNTAX: Run REPZIP exactly as you would PKZIP.");
  43.     puts("               Instead of a single Zipfile name, you may");
  44.     puts("               specify a wildcard filespec for example:");
  45.     puts("\n       <C:\\TELIX\\DOWN> REPZIP -d CPP*.ZIP README.*");
  46.     puts("\n       This will delete all files matching README.* from all");
  47.     puts("       Zipfiles matching CPP*.ZIP.");
  48.     puts("\n       The documentation provides further examples.");
  49.     puts("\n");
  50.     puts("\n");
  51. }
  52.  
  53. #define    ABORT    0
  54.  
  55. int
  56. ctrl_break(void)
  57. {
  58.     puts("\n");
  59.     puts("User BREAK.  Terminating ...");
  60.     return(ABORT);
  61. }
  62.  
  63. void
  64. chk4brk()
  65. /*    This function does an input status check.  Break handler is called
  66.     if Ctrl-C or Ctrl-Break pressed.    */
  67. {
  68.     _AH=0x0B;
  69.     geninterrupt(0x21);
  70. }
  71.  
  72.  
  73. /*    Pointer to list of arguments to be passed through to PKZIP.     */
  74.  
  75.     char    **arguments;
  76.  
  77.     char    *nullarg="  ";
  78.  
  79. void
  80. main(int argc, char **argv)
  81. {
  82.     int done,i,argnum;
  83.     struct ffblk ffblk;
  84.     char name[25], zipname[50], ext[10];
  85.     
  86.     if( argc<2 || !strcmp(argv[1],"-?"))
  87.     {
  88.         syntax();
  89.         exit(1);
  90.     }
  91.  
  92.     /*    Allocate memory for the list of argument pointers    */
  93.  
  94.     if( !(arguments = (char **)malloc( (argc+10)*sizeof(*arguments)) ) )
  95.     {
  96.         puts("\nOut of memory.  Terminating.");
  97.         exit(1);
  98.     }
  99.  
  100.     /* Set up the command line for PKZIP ... */
  101.     
  102.     argnum=0;
  103.     arguments[argnum++]=nullarg;    /* Must add a null argument at front */
  104.  
  105.     /* First add switches to command line arguments */
  106.     for( i=1; i<argc && *argv[i]=='/' || *argv[i]=='-'; i++)
  107.         arguments[argnum++]=argv[i];
  108.  
  109.     /* Next add the address to be used to pass the Zipfile name */
  110.     strcpy(zipname, argv[i]);
  111.     arguments[argnum++]=name;
  112.     if( !zipname[0] )
  113.     {
  114.         puts("\nREPZIP: You must specify a zipfile name (use * for all).");
  115.         puts("\n");
  116.         exit(1);
  117.     }
  118.  
  119.     /* Next add the rest of the arguments passed in order. */
  120.     while( i<argc )
  121.         arguments[argnum++]=argv[++i];
  122.  
  123.     /* Finally, add a NULL pointer to signify end of the list. */
  124.     arguments[argnum]=NULL;    /* Signal end of argument list */
  125.  
  126.     /* The default extension is ZIP.  User can choose another */
  127.     get_ext(zipname, ext);
  128.     if( !*ext )
  129.         strcat(zipname,".ZIP");
  130.  
  131.     done=findfirst(zipname,&ffblk,0);
  132.     name[0]='\0';
  133.     ctrlbrk(ctrl_break);
  134.     while (!done)
  135.     {
  136.         strcpy(name,ffblk.ff_name);
  137.         spawnvp(P_WAIT, PROGNAME, arguments);
  138.         done=findnext(&ffblk);
  139.         chk4brk();
  140.     }
  141.     if( !name[0] )
  142.     {
  143.         puts("\nREPZIP: No zipfiles found that match: ");
  144.         puts(zipname);
  145.         puts("\n");
  146.         exit(1);
  147.     }
  148. }